<template>
	<view class="c-wrap">
		<view class="c-block-full">
			<u-cell-group>
				<view v-for="(item, index) in sr.list" :key="index">
					<u-cell 
						:title="(index+1)+'.'+$u.timeFormat(item.createtime, 'yyyy/mm/dd hh:MM:ss')"
						:label="$t('clogin.dict.cloginuserlog_'+item.usertype)+': '+item.content"
						isLink
						:url="'/pages/clogin/cloginuserlogdetail?id='+item.id"
						></u-cell>
				</view>
			</u-cell-group>
			<view class="c-nodata" v-if="sr.list==null||sr.list.length==0">{{$t('ccore.label.nodata')}}</view>
			<u-loadmore v-if="sr.list!=null&&sr.list.length>0" :status="param.loadmore.status"
				:loadmoreText="$t('ccore.label.loadmore_loadmoreText')"
				:loadingText="$t('ccore.label.loadmore_loadingText')"
				:nomoreText="$t('ccore.label.loadmore_nomoreText')" />
		</view>
	</view>
</template>

<script>
	//page.json:  "enablePullDownRefresh": true
	export default {
		data() {
			return {
				options: null,
				sp: {

				},
				param: {
					loadmore: {
						status: 'loadmore',
						page: 0,
					}
				},
				sr: {
					list: []
				}
			}
		},
		onLoad(options) {
			let that = this;
			that.options = options;
			uni.setNavigationBarTitle({
				title: that.$t('clogin.label.cloginuserloglist')
			})
		},
		onShow() {
			let that = this;
			that.cinit();
		},
		onPullDownRefresh() {
			let that = this;
			setTimeout(function() {
				that._initPage();
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onReachBottom() {
			let that = this;
			that._loadmore(true);
		},
		methods: {
			cinit() {
				let that = this;
				that._initPage(false, true);
				return;
			},
			_loadmore:function(isReachBottom){
				let that = this;
				if(isReachBottom){
					that.param.loadmore.page++;
					that._initPage(false, false);	
				}else{
					setTimeout(function(){
						if(that.param.loadmore.page==0){
							that.param.loadmore.page++;
							that._initPage(false, false);
						}
					},3000);
				}
			},
			_initPage(isForceDisplay, isRefresh) {
				let that = this;
				that.$u.c.ajaxget('csmwj/cloginuser/pagecloginuserloglist', {
					page: (isRefresh ? 0 : that.param.loadmore.page)
				}, function(res) {
					that.param.loadmore.status = (res.list.length == 0) ? 'nomore' : 'loading';
					that.sr.list = isRefresh ? res.list : [...that.sr.list, ...res.list];
					that._loadmore(false);
				});
			},
		}
	}
</script>

<style lang="scss">

</style>
